<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="../layui/css/layui.css" rel="stylesheet" />

</head>
<body>
<div>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">科室</label>
                <div class="layui-input-block">
                    <select name="rm" id="rm"  lay-filter="xmFilter">
                        <option value=""></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">诊室名称</label>
                <div class="layui-input-block">
                    <input type="text" name="rmName"  id="rmName"  class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <select name="status" id="status"  lay-filter="xmFilter">
                        <option value="1">启用</option>
                        <option value="0">停用</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
                </div>
            </div>
        </div>
    </form>
</div>


<script src="../js/jquery.min.js"></script>
<script src="../layui/layui.js"></script>
<script>
    layui.use(['form', 'upload', 'layer','table'],function(){
        var form = layui.form;
        $.ajax({
            url: 'http://localhost:8090/role/role',
            type: 'post',
            success: function (data) {
                console.log(data);//下面会提到这个data是什么值
                //使用循环遍历，给下拉列表赋值
                $.each(data.data, function (index, value) {
                    //console.log(data.data);
                    $('#rm').append(new Option(value.name));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        })

        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                url:'http://localhost:8090/clinic/insertRoom',
                type:'post',
                data:data.field,
                success:function (param){
                    layer.closeAll('dialog');
                    console.log(param)
                    if(param.data>= 1){
                        alert("添加成功")
                    }
                }
            })
            return false;
        });
    });


</script>
</body>
</html>